import Vue from 'vue'
import VueRouter from 'vue-router'

import { Layout } from '@/layouts/index'

import NextPageInfo from './next-page/routes'

Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}

export const routes = [
  ...NextPageInfo,
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login'),
    hidden: true
  },
  {
    path: '/personal',
    name: 'personal',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'center',
        name: 'personalCenter',
        component: () => import('@/views/personal/index'),
        meta: {
          title: '个人中心'
        }
      }
    ]
  },
  {
    path: '/authz/oauth2approve',
    name: 'login',
    component: () => import('@/views/login/authorisation.vue'),
    hidden: true
  },
  {
    path: '/callback/:provider',
    name: 'callback',
    component: () => import('@/views/login/callback.vue'),
    hidden: true
  },
  {
    path: '/authenticaUser',
    name: 'authenticaUser',
    component: () => import('@/views/login/authenticaUser.vue'),
    hidden: true
  },
  {
    path: '/updatePass',
    name: 'updatePass',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'index',
        name: 'updatePass',
        component: () => import('@/views/updatePass'),
        meta: {
          title: '修改密码'
        }
      }
    ]
  },
  {
    path: '/formatPass',
    name: 'formatPass',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'index',
        name: 'formatPass',
        component: () => import('@/views/formatPass'),
        meta: {
          title: '密码重置'
        }
      }
    ]
  },
  {
    path: '/systemConfig',
    name: 'systemConfig',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'index',
        name: 'systemConfig',
        component: () => import('@/views/systemConfig/index'),
        meta: {
          title: '系统配置'
        }
      }
    ]
  },
  {
    path: '/',
    name: 'root',
    redirect: '/index/main',
    hidden: true
  },
  {
    path: '/index',
    name: 'index',
    component: Layout,
    hidden: false,
    meta: {
      title: 'Dashboard',
      icon: 'Dashboard',
      isSingle: true,
    },
    children: [
      {
        path: 'main',
        name: 'Main',
        component: () => import('@/views/index'),
        meta: {
          title: '主控台',
          logo: "../../../../static/imgIcon/app01.png",
          affix: true,
          cacheable: true
        }
      },
      // {
      //   path: 'workplace',
      //   name: 'WorkPlace',
      //   component: () => import('@/views/index/work-place'),
      //   meta: {
      //     title: '工作台',
      //     cacheable: true
      //   }
      // }
    ]
  },
  {
    path: '/list',
    name: 'list',
    component: Layout,
    hidden: false,
    meta: {
      icon: 'list',
      isSingle: true,
    },
    children: [
      {
        path: '/list/table',
        name: '表格',
        component: () => import('@/views/list/table'),
        meta: {
          logo: "../../../../static/imgIcon/app02.png",
          title: '表格',
          cacheable: true
        }
      },
    ]
  },
  {
    path: '/list2',
    name: 'list2',
    hidden: false,
    component: Layout,
    meta: {
      icon: 'list',
      isSingle: true,
    },
    children: [
      {
        path: '/list/table-with-search',
        name: '表格搜索',
        component: () => import('@/views/list/table-with-search'),
        meta: {
          logo: "../../../../static/imgIcon/app03.png",
          title: '表格搜索',
          cacheable: true
        }
      },
    ]
  },
  {
    path: '/list3',
    name: 'list3',
    hidden: false,
    component: Layout,
    meta: {
      icon: 'list',
      isSingle: true,
    },
    children: [
      {
        path: '/list/grid-list',
        name: '卡片列表',
        component: () => import('@/views/list/grid-list'),
        meta: {
          logo: "../../../../static/imgIcon/app04.png",
          title: '卡片列表',
          cacheable: true
        }
      },
    ]
  },
  {
    path: '/form',
    name: 'form',
    component: Layout,
    hidden: false,
    meta: {
      icon: 'form',
      isSingle: true,
    },
    children: [
      {
        path: '/form/base-form-view',
        name: '基本表单',
        component: () => import('@/views/form/base-form-view'),
        meta: {
          logo: "../../../../static/imgIcon/app05.png",
          title: '基本表单',
          cacheable: true
        }
      },
    ]
  },
  {
    path: '/form2',
    name: 'form2',
    hidden: false,
    component: Layout,
    meta: {
      icon: 'form',
      isSingle: true,
    },
    children: [
      {
        path: '/form/advance-form',
        name: '高级表单',
        component: () => import('@/views/form/advance-form'),
        meta: {
          logo: "../../../../static/imgIcon/app06.png",
          title: '高级表单',
          cacheable: true
        }
      },
    ]
  },
  {
    path: '/form3',
    name: 'form3',
    component: Layout,
    hidden: false,
    meta: {
      icon: 'form',
      isSingle: true,
    },
    children: [
      {
        path: '/form/step-form',
        name: '分步表单',
        component: () => import('@/views/form/step-form'),
        meta: {
          logo: "../../../../static/imgIcon/app07.png",
          title: '分步表单',
          cacheable: true
        }
      },
    ]
  },
  {
    path: '/form4',
    name: 'form4',
    component: Layout,
    hidden: true,
    meta: {
      icon: 'form',
      isSingle: true,
    },
    children: [
      {
        path: '/form/tip',
        name: '通知提示',
        component: () => import('@/views/form/tip'),
        meta: {
          logo: "../../../../static/imgIcon/app08.png",
          title: '通知提示',
          cacheable: true
        }
      },
    ]
  },
  // {
  //   menuUrl: '/form',
  //   menuName: '表单页面',
  //   tip: 'circle',
  //   icon: 'form',
  //   children: [
  //     {
  //       menuUrl: '/form/base-form-view',
  //       menuName: '基本表单',
  //       cacheable: true
  //     },
  //     {
  //       menuUrl: '/form/advance-form',
  //       menuName: '高级表单',
  //       cacheable: true
  //     },
  //     {
  //       menuUrl: '/form/step-form',
  //       menuName: '分步表单'
  //     },
  //     {
  //       menuUrl: '/form/tip',
  //       menuName: '通知提示'
  //     }
  //   ]
  // },
  // {
  //   menuUrl: '/editor',
  //   menuName: '编辑器',
  //   tip: '12',
  //   icon: 'editor',
  //   children: [
  //     {
  //       menuUrl: '/editor/rich-text',
  //       menuName: '富文本'
  //     },
  //     {
  //       menuUrl: '/editor/markdown',
  //       menuName: 'markdown'
  //     }
  //   ]
  // },
  // {
  //   menuUrl: '/other',
  //   menuName: '其它功能',
  //   children: [
  //     {
  //       menuUrl: '/other/print',
  //       menuName: '打印'
  //     },
  //     {
  //       menuUrl: 'http://www.baidu.com',
  //       menuName: '外链'
  //     },
  //     {
  //       menuUrl: '/other/qrcode',
  //       menuName: '二维码'
  //     },
  //     {
  //       menuUrl: '/other/css-animation',
  //       menuName: 'Css动画'
  //     }
  //   ]
  // }
]

const createRouter = () => new VueRouter({
  mode: 'history',
  // base:"authentication",
  scrollBehavior: () => ({ y: 0 }),
  routes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}

export default router
